package com.ruoyi.oos.web.controller.duty;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oos.duty.domain.DutyClasses;
import com.ruoyi.oos.duty.domain.DutyTurnShowBean;
import com.ruoyi.oos.duty.domain.DutyTurns;
import com.ruoyi.oos.duty.mapper.DutyClassesMapper;
import com.ruoyi.oos.duty.service.IDutyTurnsService;

/**
 * 轮值倒班信息Controller
 * 
 * @author bulang
 * @date 2020-04-29
 */
@Controller
@RequestMapping("/duty/turns")
public class DutyTurnsController extends BaseController
{
    private String prefix = "duty/turns";

    @Autowired
    private IDutyTurnsService dutyTurnsService;
    @Autowired
    private DutyClassesMapper classesMapper;

    @RequiresPermissions("duty:turns:view")
    @GetMapping()
    public String turns()
    {
        return prefix + "/turns";
    }

        /**
     * 查询轮值倒班信息列表
     */
 
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DutyTurns dutyTurns)
    {
        startPage();
        List<DutyTurnShowBean> list = dutyTurnsService.getDutyTurnsByOrder(dutyTurns);
        return getDataTable(list);
    }
    
    /**
     * 导出轮值倒班信息列表
     */
   
    @Log(title = "轮值倒班信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DutyTurns dutyTurns)
    {
        List<DutyTurns> list = dutyTurnsService.selectDutyTurnsList(dutyTurns);
        ExcelUtil<DutyTurns> util = new ExcelUtil<DutyTurns>(DutyTurns.class);
        return util.exportExcel(list, "turns");
    }

    /**
     * 新增轮值倒班信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存轮值倒班信息
     */
   
    @Log(title = "轮值倒班信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Integer data1,Integer data2,Integer data3,Integer data4,Integer orderno)
    {
        return toAjax(dutyTurnsService.insertDutyTurnsNew(data1,data2,data3,data4,orderno));
    }

    /**
     * 修改轮值倒班信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
    	List<DutyTurnShowBean> dutyTurns = dutyTurnsService.getDutyTurnsByOrderId(id);
        mmap.put("dutyTurns", dutyTurns.get(0));
        return prefix + "/edit";
    }

    /**
     * 修改保存轮值倒班信息
     */
   
    @Log(title = "轮值倒班信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Integer data1,Integer data2,Integer data3,Integer data4,Integer orderid)
    { 
    	dutyTurnsService.deleteDutyTurnsByOrderNo(orderid);
    	 return toAjax(dutyTurnsService.insertDutyTurnsNew(data1,data2,data3,data4,orderid));
    }

    /**
     * 删除轮值倒班信息
     */
    
    @Log(title = "轮值倒班信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dutyTurnsService.deleteDutyTurnsByIds(ids));
    }
    
    @GetMapping("/dutyDetail")
    public  String dutyDetail(ModelMap map) {
  		map.put("startTime", DateUtils.getDate());
  		map.put("endTime", DateUtils.getDate());
    	  return prefix + "/dutyDetail";
    	
    }
    
    /**
  * 查询轮值倒班信息列表
  */
 @PostMapping("/getdutyDetail")
 @ResponseBody
 public TableDataInfo getdutyDetail(Long dutyId,String startTime ,String endTime){
     startPage();
     List<Map<String,Object>> list = dutyTurnsService.getdutyDetail(dutyId,startTime,endTime);
     return getDataTable(list);
 }
 
    
}
